import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import bit.study.MemberDTO;

public class JSONTest03 {
	public static void main(String[] args) {
		MemberDTO dto1 = new MemberDTO("홍길순", 35, "010-4444-5555", "광주 광산구 신가동");
		JSONObject obj = new JSONObject();

		obj.put("mem", dto1);
		MemberDTO dto2 = new MemberDTO("나길순", 32, "010-4444-5555", "광주 광산구 신가동");
		MemberDTO dto3 = new MemberDTO("홍길동", 43, "010-4444-5555", "광주 광산구 신가동");
		JSONArray array = new JSONArray();
		obj.put("mem", dto1);
		array.add(obj);
		obj.put("mem", dto2);
		array.add(obj);
		obj.put("mem", dto3);
		array.add(obj);
		
		for (int i = 0; i < array.size(); i++) {
			JSONObject ob = (JSONObject)array.get(i);
			//ob를 MemberDTO로 바꾼다
			ob=(JSONObject) ob.get("mem");
			//toBean(ob를 원 클래스로 바꾼다)
			MemberDTO dto = (MemberDTO) JSONObject.toBean(ob, MemberDTO.class);
			System.out.println(dto.getName()+"\t"+dto.getAge()+"\t"+dto.getTel()+"\t"+dto.getAddr());
			
//			System.out.println(ob.get("name")+"\t"+ob.get("age")+"\t"+ob.get("tel")+"\t"+ob.get("addr"));
		}
	}
}